<?php
include("include/conn.php");
require('include/Smarty/libs/Smarty.class.php');
require('amountToWords.php');

$billMst    = array();
$billDetail = array();
$billForm   = "";

$selectBill = "SELECT billMstId, partyName, partyAdd, partyTinNo, billNo, DATE_FORMAT(billDate,'%d-%m-%Y')AS billDate, totalAmount, vatInPer, vatTotal, cstInPer, cstTotal, grossTotal, 
                      amountInWord,invoice,notes
                 FROM billmstom
                WHERE billMstId = ".$_GET['billId'];
$selectBillRes = mysql_query($selectBill);
if($billRow = mysql_fetch_assoc($selectBillRes))
{
	$billmst['partyName']     = $billRow['partyName'];
	$billmst['partyAdd']      = $billRow['partyAdd'];
	$billmst['partyTinNo']    = $billRow['partyTinNo'];
	$billmst['billNo']        = $billRow['billNo'];
	$billmst['billDate']      = $billRow['billDate'];
	$billmst['totalAmount']   = formatInIndianStyle(round($billRow['totalAmount']),0);
	$billmst['vatInPer']      = $billRow['vatInPer'];
	$billmst['vatTotal']      = formatInIndianStyle(round($billRow['vatTotal']),0);
	$billmst['cstInPer']      = $billRow['cstInPer'];
	$billmst['cstTotal']      = formatInIndianStyle(round($billRow['cstTotal']),0);
	$billmst['grossTotal']    = formatInIndianStyle(round($billRow['grossTotal']),0);
	$billmst['invoice']       = $billRow['invoice'];
	$billmst['notes']         = $billRow['notes'];
	$billmst['amountInWords'] = ucwords(words(round($billRow['grossTotal'],0)));
}

$selectBillDetail = "SELECT billMstId, particular, hnsCode, grossWeight, fineWeight, rate, amount 
                       FROM billmstdetailom
                      WHERE billMstId = ".$_GET['billId'];
$selectBillDetailRes =mysql_query($selectBillDetail);
$a = 0;

while($billDetailRow = mysql_fetch_assoc($selectBillDetailRes))
{
	$billDetail[$a]['particular']  = $billDetailRow['particular'];
	$billDetail[$a]['hnsCode']     = $billDetailRow['hnsCode'];
	$billDetail[$a]['grossWeight'] = $billDetailRow['grossWeight'];
	$billDetail[$a]['fineWeight']  = $billDetailRow['fineWeight'];
	$billDetail[$a]['rate']        = formatInIndianStyle(round($billDetailRow['rate']),0);
	$billDetail[$a]['amount']      = formatInIndianStyle(round($billDetailRow['amount']),0);
	$a++;
}
$billDetailRowCount = $a;

$addBr = "&nbsp;";
for($i = $billDetailRowCount; $i <= 10; $i++)
  $addBr .= "<br />";

$smarty = new Smarty;
require("bottom.php");

$smarty->assign("billmst",$billmst);
$smarty->assign("billDetail",$billDetail);
$smarty->assign("addBr",$addBr);
$smarty->assign("billForm",$billForm);
$smarty->display("billOriginalOmDetail.tpl");
?>